/*
 * Runtimer.h
 *
 *  Created on: Nov 29, 2012
 *      Author: bouchier
 */
/*!
 * \file Runtimer.h
 * \brief The header file for the Runtimer class
 */

#ifndef RUNTIMER_H_
#define RUNTIMER_H_
typedef unsigned long tick_t;

/*!
 * \class Runtimer
 * \brief The class which allows timing sections of code over multiple iterations
 *
 * This class records & accumulates runtime data for sections of code. Instantiate it with a name that
 * identifies the section of code being instrumented. Then call start() to begin timing a code segment,
 * and stop() to end the timing run. It maintains a count of the number of times the code segment has
 * run, accumulated time, maximum time, and how many times the code took more than 20ms to run. The
 * print() method prints this data, and may be called periodically to get a statistical look at
 * execution.
 */
class Runtimer {
public:
	Runtimer(char * name);
	virtual ~Runtimer();
	void start();
	void stop();
	void print();
	void clear();
    unsigned long getCount() const
    {
        return count;
    }

private:
	tick_t startTick;
	unsigned long cumulative;
	unsigned long biggest;
	int numOver20Ms;
	unsigned long count;
	unsigned long lastMs;
	char *timerName;

};

#endif /* RUNTIMER_H_ */
